﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JMY_BLL;
using JMY_Models;
using Newtonsoft.Json;
namespace HospitalPeoject.Controllers
{
    public class DocInfosController : Controller
    {
        // GET: DocInfos
        public ActionResult Index()
        {

            var xianzia = DateTime.Now; 

            return View();
        }
        public ActionResult DocLogin()
        {
            return View();
        }
        [HttpPost]
        public JsonResult DocLogin(string LogName, string LogPwd)
        {


            var data = new JMY_BLL.DocLoginBLL().DocLogins(LogName,LogPwd);
            if (data > 0)
            {
                return Json(new { code = 1, message = "恩恩" });
            }
            else
            {
                return Json(new { code = 0, message = "asd" });
            }
            
        }
       
        public ActionResult MainInfo()
        {
            return View();
        }
        /// <summary>
        /// 主页
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowMain()
        {
            return View();
        }
        /// <summary>
        /// 医院管理
        /// </summary>
        /// <returns></returns>
        public ActionResult DocGuanLi()
        {
            return View();
        }
        

        /// <summary>
        /// 医院管理员平台
        /// </summary>
        /// <returns></returns>
        ///
        [HttpGet]
        public ActionResult DocGuanLiYuan()
        {
           

            
            return View();
        }



        //public ActionResult DocDiscount()
        //{
        //    //接收到数据库中的优惠券类型
        //    var datalist = new JMY_BLL.T_Discount_TypeInfosBll().Get_Discount_Type();

        //    return View();
        //}


        /// <summary>
        /// 显示管理人员信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string DocGuanLiYuanshow()
        {
            List<T_Doc_Logins_Model> login= new JMY_BLL.DocLoginBLL().DocGuanLiYuanShow();


            return JsonConvert.SerializeObject(login);
        }
        /// <summary>
        /// 添加管理人员信息
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DocGuanLiYuanAdd(string name ,string pwd)
        {
            int n = new JMY_BLL.DocLoginBLL().DocGuanLiYuanAdd(name, pwd);
            if(n>0)
            {
                return Content("<script>alert('添加成功');location.href='/DocInfos/DocGuanLiYuan';</script>");
            }
            else
            {
                return Content("<script>alert('添加失败');location.href='/DocInfos/DocGuanLiYuan';</script>");
            }
        }
        /// <summary>
        /// 删除管理人员信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult  DocGuanLiYuanDel(int id)
        {
            int n = new JMY_BLL.DocLoginBLL().DocGuanLiYuanDel(id);
            if (n > 0)
            {
                return Content("<script>alert('删除成功');location.href='/DocInfos/DocGuanLiYuan';</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/DocInfos/DocGuanLiYuan';</script>");
            }
        }
        /// <summary>
        /// 修改管理人员信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public string DocGuanLiYuanUpt1(int id)
        {
            List<T_Doc_Logins_Model> login = new JMY_BLL.DocLoginBLL().DocGuanLiYuanUpt1(id);


            return JsonConvert.SerializeObject(login);
        }
        [HttpPost]
        public ActionResult DocGuanLiYuanUpt2(int id, string name ,string pwd)
        {
            T_Doc_Logins_Model m = new T_Doc_Logins_Model();
            m.T_DOC_ID = id;
            m.T_DOC_UserName = name;
            m.T_DOC_UserPwd = pwd;
            int n = new JMY_BLL.DocLoginBLL().DocGuanLiYuanUpt2(m);
            if (n > 0)
            {
                return Content("<script>alert('修改成功');location.href='/DocInfos/DocGuanLiYuan';</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');location.href='/DocInfos/DocGuanLiYuan';</script>");
            }
            
            
        }

        



        /// <summary>
        /// 优惠券管理
        /// </summary>
        /// <returns></returns>
        public ActionResult DocDiscount()
        {
            
            var data = new JMY_BLL.T_Discount_InfosBll().GetDiscount_Infor();
           // ViewBag.list = data;
            return View(data);
        }
        public ActionResult AddDocDiscount()
        {
            return View();
        }
        [HttpPost]
        public ActionResult AddDocDiscount(JMY_Models.T_Discount_Infos_Model p)
        {

            int i = new JMY_BLL.T_Discount_InfosBll().AddDiscount_Infor(p);
            if (i > 0)
            {
                return Content("<script>alert('添加成功');location.href='/DocInfos/DocDiscount'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败')</script>");
            }
        }

        public ActionResult DelDocDiscount(int T_Discount_ID)
        {
            var i = new JMY_BLL.T_Discount_InfosBll().DelDiscount_Infor(T_Discount_ID);
            if(i>0)
            {
                return Content("<script>alert('删除成功');location.href='/DocInfos/DocDiscount'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败')</script>");
            }
        }
 
        public ActionResult FanTian(int id)
        {
            ViewBag.bianhao = id;
            var datalist = new JMY_BLL.T_Discount_InfosBll().ShowDic(id);
            var xinxi = datalist.Where(T => T.T_Discount_ID == id).FirstOrDefault();
            var T_name = xinxi.T_Discount_Name;
            var T_Type = xinxi.T_Discount_Type;
            var T_edu = xinxi.T_Discount_Limit;

            ViewBag.T_Dname = T_name;
            ViewBag.T_Dtype = T_Type;
            ViewBag.T_Edu = T_edu;
   
            return View();
        }
        [HttpPost]
        public ActionResult FanTian(JMY_Models.T_Discount_Infos_Model p)
        {
            var i = new JMY_BLL.T_Discount_InfosBll().UpdateDiscount_Infor(p);
            if (i > 0)
            {
                return Content("<script>alert('修改成功');location.href='/DocInfos/DocDiscount'</script>");
            }
            else
            {
                return Content("<script>alert('修改失败')</script>");
            }
        }




        /// <summary>
        /// 储蓄卡管理
        /// </summary>
        /// <returns></returns>
        public ActionResult DocOrderForm()
        {
            return View();
        }
        /// <summary>
        /// 订单管理
        /// </summary>
        /// <returns></returns>
        public ActionResult DingDan(string stime="2001-1-30",string etime="2999-1-6", int sid = 0, int yid = 0)
        {
          
            
            T_OrderForm_Infos_BLL to = new T_OrderForm_Infos_BLL();
            var result = to.OrderFormShow(sid,yid,stime,etime);
            
            return View(result);
        }
        //[HttpPost]
        //public JsonResult DingDan(int sid)
        //{
        //    T_OrderForm_Infos_BLL to = new T_OrderForm_Infos_BLL();
        //    var result = to.OrderFormShow(sid);
        //    if ()
        //    {

        //    }     
           
        //}

        /// <summary>
        /// 获取状态
        /// </summary>
        /// <returns></returns>
        public JsonResult GetState()
        {
            T_OrderForm_Infos_BLL to = new T_OrderForm_Infos_BLL();
            return Json(to.GetState(), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 获取医院
        /// </summary>
        /// <returns></returns>
        public JsonResult GetHospital()
        {
            T_OrderForm_Infos_BLL to = new T_OrderForm_Infos_BLL();
            return Json(to.GetHospital(),JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 团检查询
        /// </summary>
        /// <returns></returns>
        public ActionResult DocBallCheck()
        {
           
            return View();

        }
        /// <summary>
        /// 文件导入
        /// </summary>
        /// <returns></returns>
        public ActionResult DocFile()
        {
            return View();
        }
        
    }
}